<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        div {
            position: absolute;
        }
    </style>
</head>
<body>
<input type="button" value="摇起来" id="btn1">
<input type="button" value="停止" id="btn2">
<div id="dv">
    <img src="./img/zbj.jpg" alt="">
</div>

<script src="common.js"></script>
<script>
    var a = 0;
    document.querySelector('#btn1').onclick = function () {
        a = setInterval(function () {
            //让图片动起来可以使div动起来
            var x = parseInt(Math.random() * 100) + 1; // 1-100随机数
            var y = parseInt(Math.random() * 100) + 1;
            dv.style.left = x + "px";
            dv.style.top = y + "px";
        }, 100);
    };
    document.querySelector('#btn2').onclick = function () {
        clearInterval(a);
    };
</script>
</body>
</html>